package com.sz.biz.app.web.filter;

import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Function: TODO: ADD FUNCTION <br>
 * Author: Charles. <br>
 * Date: 2017-10-31 16:12:00.
 */
public class XssFilter  extends OncePerRequestFilter {

    private List<String> whiteList = new ArrayList<>();

    public XssFilter(List<String> whiteUrlList) {
        if (whiteUrlList != null && whiteUrlList.size() > 0) {
            this.whiteList.addAll(whiteUrlList);
        }
    }

    @Override
    protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException {
        filterChain.doFilter(new XssHttpServletRequestWrapper(httpServletRequest,whiteList), httpServletResponse);
    }
}
